package cn.com.zpark.servlet_config;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @PackageName: cn.com.zpark.servlet_config
 * @ClassName: ServletConfigDemo03
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  10:54
 */
@WebServlet(urlPatterns = "/scd3.do", initParams = {
        @WebInitParam(name = "dc", value = "大锤"),
        @WebInitParam(name = "msg", value = "哈哈哈哈哈"),
})
public class ServletConfigDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取servletConfig对象
        ServletConfig servletConfig = getServletConfig();
        // 获取初始胡啊参数的枚举值，参数名字的枚举集合
        Enumeration<String> names = servletConfig.getInitParameterNames();
        while (names.hasMoreElements()) {
            // 获取参数名字
            String name = names.nextElement();
            // 根据参数名字获取参数的值
            String value = servletConfig.getInitParameter(name);
            System.out.println(name+": "+value);

        }

    }
}
